package itsm.isperp.module.controller.app;

import itsm.isperp.framework.web.controller.BaseController;
import itsm.isperp.framework.web.response.ResultMessage;
import itsm.isperp.module.entity.app.AppUserDefGrid;
import itsm.isperp.module.service.app.AppUserDefGridService;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 控制器
 * 
 * @author lizx
 * @date 2015-11-24 14:07
 */
@Controller
@RequestMapping("app/userDefGrid")
public class AppUserDefGridController extends BaseController<AppUserDefGrid> {

	@Autowired
	protected AppUserDefGridService appUserDefGridService;

	@Override
	public AppUserDefGridService getService() {
		return this.appUserDefGridService;
	}

	@Override
	public String getPageTitle() {
		return "个人自定义grid";
	}

	/**
	 * 保存用于自定义grid
	 * 
	 * @param model
	 *            实体
	 * @param req
	 *            数据请求
	 * 
	 * @return 返回{@link ResultMessage}
	 */
	@RequestMapping("save")
	@ResponseBody
	@Override
	public ResultMessage save(AppUserDefGrid model, HttpServletRequest req) {

		this.getService().saveOrUpdate(model, req);
		return ResultMessage.newInstance(true, null, model.getId());
	}

	/**
	 * 获取用户的自定义grid
	 * 
	 * @param url
	 *            页面地址
	 * @param gridId
	 *            grid标识
	 * @param req
	 *            页面请求
	 * @return 如果存在返回key为“col_model”和“page_size”的map，否则返回null
	 */
	@RequestMapping("findUserDefGrid")
	@ResponseBody
	public Map<String, Object> findUserDefGrid(String url, String gridId,
			HttpServletRequest req) {

		return this.getService().findUserDefGrid(url, gridId);
	}

	@RequestMapping("deleteUserDefGrid")
	@ResponseBody
	public ResultMessage deleteUserDefGrid(String url, String gridId,
			HttpServletRequest req) {
		return this.getService().deleteUserDefGrid(url, gridId);
	
	}
}
